package com.zhw.goshopping.controller;

import com.zhw.goshopping.common.pojo.EasyUITreeNode;
import com.zhw.goshopping.common.pojo.GoShoppingResult;
import com.zhw.goshopping.content.service.ContentCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Create by zhaihongwei on 2018/3/24
 */
@Controller
public class ContentCategoryController {

    @Autowired
    private ContentCategoryService contentCategoryService;

    /**
     * 查询网站内容管理树的所有节点
     * @param parentId
     * @return
     */
    @RequestMapping("/content/category/list")
    @ResponseBody
    public List<EasyUITreeNode> getContentCategoryList(@RequestParam(value ="id",defaultValue = "0")long parentId) {
        List<EasyUITreeNode> categoryList = contentCategoryService.getContentCategoryList(parentId);
        return categoryList;
    }

    /**
     * 添加网站内容管理树的节点
     * @param parentId
     * @param name
     * @return
     */
    @RequestMapping("/content/category/create")
    @ResponseBody
    public GoShoppingResult addContentCategory(long parentId,String name) {
        GoShoppingResult result = contentCategoryService.addContentCategory(parentId,name);
        return result;
    }

    /**
     * 修改网站内容管理树名称
     * @param id
     * @param name
     * @return
     */
    @RequestMapping("/content/category/update")
    @ResponseBody
    public void updateContentCategory(long id,String name) {
        contentCategoryService.updateContentCategory(id,name);
    }

    /**
     * 删除网站内容管理树名称
     * @param id
     * @return
     */
    @RequestMapping("/content/category/delete")
    @ResponseBody
    public GoShoppingResult updateContentCategory(long id) {
        boolean flag = contentCategoryService.deleteContentCategory(id);
        if (!flag) {
            return null;
        }else {
            return GoShoppingResult.ok();
        }
    }

}
